function $(selector) {
	var result = document.querySelectorAll(selector);
	if (result.length === 1) { /**根据元素长度输出为Node节点还是NodeList节点**/
		return result[0]
	}
	return result;
}

function bindEvent(nodeList, eventType, fn) {
	for (var i = 0; i < nodeList.length; i++) {
		nodeList[i][eventType] = fn
		// 常量 对象名.属性相当于对象名["属性"]  变量 对象名[属性]
	}
}
// 十六进制随机颜色值
function getRandomColor() {
	var arr = ["0", "1", "2", "3", "4", "5", "6", "7", "8", "9", "a", "b", "c", "d", "e", "f"];
	var result = "#";
	for (var i = 0; i < 6; i++) {
		var index = Math.floor(Math.random() * 16)
		result = result + arr[index];
	}
	return result;
}
// 四位随机验证码
function getRandomNum() {
	var result = "";
	var arr = ["0", "1", "2", "3", "4", "5", "6", "7", "8", "9", "a", "b", "c", "d", "e", "f",
		"g", "h", "i", "j", "k", "l", "m", "n", "o", "p", "q", "r", "s", "t", "u", "v", "w", "x", "y", "z",
		"A", "B", "C", "D", "E", "F", "G", "H", "I", "J", "K", "L", "M", "N", "O", "P", "Q", "R", "S", "T", "U", "V", "W",
		"X", "Y", "Z"];
	for (var i = 0; i < 4; i++) {
		var index = parseInt(Math.random() * arr.length);
		result += arr[index];
	}
	return result;
}

// 查询数组中是否有该元素，创建方法
Array.prototype.has = function(query){
	let isHas = false;
	// 指向 实例对象 : 数组
	this.forEach(item=>{
		if(item === query){
			isHas = true;
		}
	})
	return isHas;
}
// 创建方法,默认为单击事件
NodeList.prototype.bind = function(eventType,fn){
	if(typeof eventType === "function" && fn === undefined){
		fn = eventType;
		eventType = "onclick";
	}
	this.forEach(item=>{
		item[eventType] = fn;
	})
	return this;
}

HTMLCollection.prototype.bind = function(eventType,fn){
	if(typeof eventType === "function" && fn === undefined){
		fn = eventType;
		eventType = "onclick";
	}
	for(let i = 0; i < this.length;i++){
		this[i][eventType]=fn;
	}
	return this;
}

// 相当于为所有元素节点扩展方法，淡入淡出
HTMLElement.prototype.fadeOut = function(speed=0.05,callback){	/**淡入**/
	if(speed === "slow"){speed = 0.02};
	if(speed === "fast"){speed = 0.08};
	if(typeof speed === "function"){
		callback = speed;
		speed = 0.05;
	}
	this.style.opacity = 1;
	let fadeOut = setInterval(()=>{
		let o = parseFloat(this.style.opacity);
		if(o <= 0){
			this.style.opacity = 0;
			this.style.display = "none";
			clearInterval(fadeOut)
			callback && typeof callback ===  "function" ? callback() : ""
			return;
		}
		this.style.opacity = o - speed;
	},16)
}
HTMLElement.prototype.fadeIn = function(speed=0.05,callback){	/**淡出**/
	if(speed === "slow"){speed = 0.02};
	if(speed === "fast"){speed = 0.08};
	if(typeof speed === "function"){
		callback = speed;
		speed = 0.05;
	}
	this.style.opacity = 0;
	this.style.display = "block";
	let fadeOut = setInterval(()=>{
		let o = parseFloat(this.style.opacity);
		if(o >= 1){
			this.style.opacity = 1 ;
			clearInterval(fadeOut)
			callback && typeof callback ===  "function" ? callback() : ""
			return;
		}
		this.style.opacity = o + speed;
	},16)
}